<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('项目分配用户')"/>
</head>
<body>
<div class="main-content">
    <form id="form-project-add" class="form-horizontal">
        <input type="hidden" id="projectId" name="projectId" th:value="${project.id}">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-5">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">项目名称：</label>
                    <div class="col-sm-8">
                        <input name="name" class="form-control" type="text" disabled th:value="${project.name}">
                    </div>
                </div>
            </div>
            <div class="col-sm-5">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">负责人：</label>
                    <div class="col-sm-8">
                        <input name="leader" class="form-control" type="text" disabled th:value="${project.leader}">
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">分配用户</h4>
        <div class="row" id="userTable">
            <div class="col-sm-12">
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler('all')"><i class="fa fa-check"></i>关联全部
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="submitHandler('clearAll')"><i
                class="fa fa-remove"></i>全部清除
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/project/authUser";
    var users = [[${users.list}]];
    var mine = [[${users.mine}]];

    $(function () {
        var options = {
            data: users,
            sidePagination: "client",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            clickToSelect: true,
            maintainSelected: true,
            onCheck: function (row) {
                mine[row.userId] = true;
            },
            onUncheck: function (row) {
                delete mine[row.userId];
            },
            columns: [{
                checkbox: true,
                formatter: function (value, row, index) {
                    return {checked: mine[row.userId]};
                }

            },
                {
                    field: 'userId',
                    title: '用户userId',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '姓名'
                },
                {
                    field: 'dept.deptName',
                    title: '部门'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                }]
        };
        $.table.init(options);
        // changeAll();
    });

    /* 添加角色-提交 */
    function submitHandler(command) {
        if (command != undefined && command != '') {
            $.modal.confirm("确认要" + (command == 'all' ? "关联" : "清除") + "全部人员?", function () {
                var data = {"projectId": $("#projectId").val(), "mine": command};
                $.operate.saveTab(prefix + "/insert", data);
            });
        } else {
            var data = {"projectId": $("#projectId").val(), "mine": Object.keys(mine).join()};
            $.operate.saveTab(prefix + "/insert", data);
        }

    }
</script>
</body>
</html>